package com.hongxun.project.assets.pPullLine.controller;

import java.util.List;
import java.util.Map;

import com.hongxun.common.utils.text.Convert;
//import com.sun.org.apache.xpath.internal.operations.Mod;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.hongxun.framework.aspectj.lang.annotation.Log;
import com.hongxun.framework.aspectj.lang.enums.BusinessType;
import com.hongxun.project.assets.pPullLine.domain.PPullLine;
import com.hongxun.project.assets.pPullLine.service.IPPullLineService;
import com.hongxun.framework.web.controller.BaseController;
import com.hongxun.framework.web.page.TableDataInfo;
import com.hongxun.framework.web.domain.AjaxResult;
import com.hongxun.common.utils.poi.ExcelUtil;

/**
 * 拉线采集 信息操作处理
 *
 * @author hongxun
 * @date 2019-03-19
 */
@Controller
@RequestMapping("/assets/pPullLine")
public class PPullLineController extends BaseController {
    private String prefix = "assets/pPullLine";

    @Autowired
    private IPPullLineService pPullLineService;

    @RequiresPermissions("assets:pPullLine:view")
    @GetMapping()
    public String pPullLine() {
        return prefix + "/pPullLine";
    }

	/*@GetMapping("/task_pPullLine/{taskId}")
    public String task_pPullLine(@PathVariable("taskId") String taskId , ModelMap modelMap)
	{
		modelMap.put("taskId",taskId);
	    return prefix + "/task-pPullLine";
	}*/

    /**
     * 查询拉线采集列表
     */
    @RequiresPermissions("assets:pPullLine:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PPullLine pPullLine) {
        startPage();
        List<PPullLine> list = pPullLineService.selectPPullLineList(pPullLine);
        return getDataTable(list);
    }


    /**
     * 导出拉线采集列表
     */
    @RequiresPermissions("assets:pPullLine:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PPullLine pPullLine) {
        List<PPullLine> list = pPullLineService.selectPPullLineList(pPullLine);
        ExcelUtil<PPullLine> util = new ExcelUtil<PPullLine>(PPullLine.class);
        return util.exportExcel(list, "pPullLine");
    }

    /**
     * 新增拉线采集
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存拉线采集
     */
    @RequiresPermissions("assets:pPullLine:add")
    @Log(title = "拉线采集", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PPullLine pPullLine) {
        pPullLine.setDatastate("新增");
        return toAjax(pPullLineService.insertPPullLine(pPullLine));
    }

    /**
     * 修改拉线采集
     */
    @GetMapping("/edit/{id}/{taskId}")
    public String edit(@PathVariable("id") String id, @PathVariable("taskId") String taskId, ModelMap mmap) {
        PPullLine pPullLine = pPullLineService.selectPPullLineByIdForState(id, taskId);
        mmap.put("pPullLine", pPullLine);
        return prefix + "/edit";
    }

    /**
     * 修改保存拉线采集
     */
    @RequiresPermissions("assets:pPullLine:edit")
    @Log(title = "拉线采集", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PPullLine pPullLine) {
        pPullLine.setDatastate("修改");
        return toAjax(pPullLineService.updatePPullLine(pPullLine));
    }

    /**
     * 删除拉线采集
     */
    @RequiresPermissions("assets:pPullLine:remove")
    @Log(title = "拉线采集", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(pPullLineService.deletePPullLineByIds(ids));
    }


    /**
     * 删除拉线采集
     */
    @RequiresPermissions("assets:pPullLine:remove")
    @Log(title = "拉线采集", businessType = BusinessType.DELETE)
    @PostMapping("/remove2Id")
    @ResponseBody
    public AjaxResult remove2Id(String ids , String taskIds) {
        String[] str = Convert.toStrArray(ids);
        int i = 0;
        for (String s : str) {
            PPullLine pPullLine = new PPullLine();
            pPullLine.setId(s);
            pPullLine.setTaskId(taskIds);
            pPullLine.setDatastate("删除");
            i = pPullLineService.updatePPullLine(pPullLine);
        }
        return toAjax(i);
//        return toAjax(pPullLineService.deletePPullLineByIdsAndTaskIds(ids , taskIds));
    }

}
